package chai.ningning.schedule;

import java.util.concurrent.TimeUnit;

public class InterruptTest {

    static class InterruptThread extends Thread{

        public InterruptThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            Thread t = Thread.currentThread();
            System.out.println("before try...catch..." + t);
            try {
                System.out.println("before sleep : "+t);
                Thread.sleep(10000);
                System.out.println("after sleep : "+t);
            }catch (InterruptedException e){
                System.out.println("interrupted : " +t);
            }
            System.out.println("after try...catch..." +t);
        }
    }

    public static void main(String[] args) throws InterruptedException {

        Thread t = new InterruptThread("秦始皇");
        t.start();

        TimeUnit.SECONDS.sleep(3);
        t.interrupt();// 中断t所引用的线程的 "阻塞状态"
    }
}
